package com.lx.provider.configs;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;

/**
 * TODO 添加描述

 * @date 2024/10/15 19:15
 */
public class FanoutRabbitConfig {
    /**
     * 创建三个队列 ：fanout.A   fanout.B  fanout.C
     * 将三个队列都绑定在交换机 fanoutExchange 上
     * 因为是扇型交换机, 路由键无需配置,配置也不起作用
     */
    /**
     * 声明队列A
     * @return
     */
    @Bean
    public Queue queueA() {
        return new Queue("fanout.A");
    }
    /**
     * 声明队列B
     * @return
     */
    @Bean
    public Queue queueB() {
        return new Queue("fanout.B");
    }

    /**
     * 声明队列C
     * @return
     */
    @Bean
    public Queue queueC() {
        return new Queue("fanout.C");
    }

    /**
     * 声明交换机fanoutExchange
     * @return
     */
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    /**
     * 队列A绑定交换机
     * @return
     */
    @Bean
    Binding bindingExchangeA() {
        return BindingBuilder.bind(queueA()).to(fanoutExchange());
    }

    /**
     * 队列B绑定交换机
     * @return
     */
    @Bean
    Binding bindingExchangeB() {
        return BindingBuilder.bind(queueB()).to(fanoutExchange());
    }

    /**
     * 队列C绑定交换机
     * @return
     */
    @Bean
    Binding bindingExchangeC() {
        return BindingBuilder.bind(queueC()).to(fanoutExchange());
    }
}
